import org.omg.Messaging.SyncScopeHelper;

public class Leet7 {
    /**
     * 整数翻转，
     * 注意翻转后整数是否超过要 整形存在的范围
     */
    public int reverse(int x) {
        String s;
        StringBuilder stringBuilder = new StringBuilder();
        char [] chars;
        Long y=0L;
        s=String.valueOf(x);
        if (x==0){
            return 0;
        }
        if(x>0){
            chars =s.toCharArray();

            for (int i=chars.length-1;i>=0;i--){
                stringBuilder.append(chars[i]);
            }
        }else{
            chars=s.toCharArray();
            stringBuilder.append("-");
            for (int i=chars.length-1;i>=1;i--){
                stringBuilder.append(chars[i]);
            }
        }

        y=Long.parseLong(stringBuilder.toString());
        if (y>-(Math.pow(2,31))&&y<(Math.pow(2,31)-1)){
            return y.intValue();
        }else {
            return 0;
        }
    }
}
